﻿using System.Windows;
using System.Diagnostics;

namespace VMDS.GUIClient.Model
{
    /// <summary>
    /// Message listener, singlton pattern.
    /// Inherit from DependencyObject to implement DataBinding.
    /// </summary>
    public class MessageListener : DependencyObject
    {
        /// <summary>
        /// 
        /// </summary>
        private static MessageListener mInstance;

        /// <summary>
        /// 
        /// </summary>
        private MessageListener ( )
        {

        }

        /// <summary>
        /// Get MessageListener instance
        /// </summary>
        public static MessageListener Instance
        {
            get
            {
                if ( mInstance == null )
                    mInstance = new MessageListener ( );
                return mInstance;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        public void ReceiveMessage ( string message )
        {
            Message = message;
            Debug.WriteLine ( Message );
            DispatcherHelper.DoEvents ( );
        }
        public void ChangeProgress(int progress)
        {
            Progress = progress;
            DispatcherHelper.DoEvents();
        }
       
        /// <summary>
        /// Get or set received message
        /// </summary>
        public string Message
        {
            get { return ( string ) GetValue ( MessageProperty ); }
            set { SetValue ( MessageProperty, value ); }
        }

        public int Progress
        {
            get { return (int) GetValue(ProgressProperty); }
            set { SetValue(ProgressProperty, value); }
        }
        /// <summary>
        /// 
        /// </summary>
        public static readonly DependencyProperty MessageProperty =
            DependencyProperty.Register("Message", typeof(string), typeof(MessageListener), new UIPropertyMetadata(null));
        public static readonly DependencyProperty ProgressProperty =
                    DependencyProperty.Register("Progress", typeof(int), typeof(MessageListener), new UIPropertyMetadata(null));

    }
}
